<?php

/*
 * litchicms
 * Copyright (C) 2010-7-7 Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
!defined('BRK') && exit("!");

if (!_filter_id()) {
    return false;
}


if (!empty($_POST['field']['coll_selected'])) {
    foreach ($_POST['field']['coll_selected'] as $value) {
        brk_update($COLLECTION_TABLENAME, array('status' => 1), "WHERE id=" . $value);
    }
}

eMsg(1, "OK!", array(1, "?" . bgpre("collac-list")));
$_POST['action'] = 'error';

$_POST['Component']['category'] = array($_POST['Component_options']['category']);
if (in_array($_POST['Component_options']['category'], $FIELDS_hidden['category']['cids'])) {
    foreach ($_POST['field']['coll_selected'] as $value) {
        $RECORD_ID = intval($value);
        brk_delete('ccc_relationships', "WHERE id=$value AND collection_id=$COLLECTION_ID");
        brk_insert('ccc_relationships', array("id" => $value, 'collection_id' => $COLLECTION_ID, 'cid' => $_POST['Component_options']['category']));
        brk_update($COLLECTION_TABLENAME, Component_buildField_category(), "WHERE id=$value");
    }
    return TRUE;
} else {
    return false;
}
